package com.cj.life.controller;

import com.cj.life.mapper.UserMapper;
import com.cj.life.pojo.dto.UserLoginDTo;
import com.cj.life.pojo.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
public class UserController {
    @Autowired(required = false)
    UserMapper mapper;
    @RequestMapping("/login")
    public int login(@RequestBody UserLoginDTo user, HttpSession session){
        System.out.println("user = " + user);
        UserVO u=mapper.selectByUsername(user.getUsername());
        if (u!=null){
            if (u.getPassword().equals(user.getPassword())){
                session.setAttribute("user",u);
                return 1;
            }
            return 2;
        }
        return 3;
    }
}
